package com.rjpacket.MyUEnjoy;

import android.app.ActionBar;
import android.app.Activity;
import android.app.FragmentTransaction;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.view.ViewPager;
import com.rjpacket.MyUEnjoy.adapters.StoreAdapter;

/**
 * Created by aaa on 15-1-23.
 */
public class StoreActivity extends FragmentActivity implements ActionBar.TabListener, ViewPager.OnPageChangeListener {

    private ViewPager pager;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.store_activity);

        pager = (ViewPager) findViewById(R.id.pager_store);
        pager.setAdapter(new StoreAdapter(getSupportFragmentManager()));

        pager.setOnPageChangeListener(this);

        ActionBar actionBar = getActionBar();
        if(actionBar != null){
            actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

            ActionBar.Tab tab = actionBar.newTab();
            tab.setText("核心产品").setTag("0");
            tab.setTabListener(this);
            actionBar.addTab(tab);

            tab = actionBar.newTab();
            tab.setText("平台产品").setTag("1");
            tab.setTabListener(this);
            actionBar.addTab(tab);
        }


        pager.setCurrentItem(0);

    }

    @Override
    public void onTabSelected(ActionBar.Tab tab, FragmentTransaction ft) {
        ActionBar actionBar = getActionBar();
        if(actionBar != null){
            int index = actionBar.getSelectedNavigationIndex();

            pager.setCurrentItem(index);
        }

    }

    @Override
    public void onTabUnselected(ActionBar.Tab tab, FragmentTransaction ft) {

    }

    @Override
    public void onTabReselected(ActionBar.Tab tab, FragmentTransaction ft) {

    }

    @Override
    public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

    }

    @Override
    public void onPageSelected(int position) {
        ActionBar actionBar = getActionBar();
        if(actionBar != null){
            actionBar.setSelectedNavigationItem(position);
        }
    }

    @Override
    public void onPageScrollStateChanged(int state) {

    }
}